from common.base import Base, By


class BackGroundPage(Base):
    # 封装表现层
    admin_name_loc = (By.NAME, 'admin_name') # 用户名输入框
    password_loc = (By.NAME, 'password') # 密码输入框
    captcha_loc = (By.NAME, 'captcha') # 验证码输入框
    login_loc = (By.XPATH, '//strong[text()="登 录"]') # 登录按钮

    member_module_loc = (By.LINK_TEXT,'会员') # 会员模块
    seller_loc = (By.XPATH,'//span[text()="商户管理"]') # 商户管理模块
    seller_list_loc = (By.LINK_TEXT,'商户列表') # 商户列表

    product_module_loc = (By.LINK_TEXT,'商品') # 商品模块


    # 封装操作层
    # 管理员登录流程
    def process_admin_login(self,acc,pwd):
        self.send_keys(BackGroundPage.admin_name_loc,acc)
        self.send_keys(BackGroundPage.password_loc,pwd)
        self.send_keys(BackGroundPage.captcha_loc,'sssss')
        self.click(BackGroundPage.login_loc)

    # 点击会员模块
    def click_member_module(self):
        self.click(BackGroundPage.member_module_loc)

    # 点击商户管理模块
    def click_seller(self):
        self.click(BackGroundPage.seller_loc)

    # 点击商户列表
    def click_seller_list(self):
        self.click(BackGroundPage.seller_list_loc)

    # 点击商品模块
    def click_product_module(self):
        self.click(BackGroundPage.product_module_loc)

    # 商品审核，将状态都设置成上架，通过select标签名，定位一组元素，批量操作
    def product_review(self,value:str='up'):
        my_list = self.find_elements((By.TAG_NAME,'select'))
        # for循环遍历my_list中保存的元素，将状态都设置成上架
        for ele in my_list:
            self.select_by_value(ele,value)


